#include "ScriptManager.h"

#include "MudBath.h"
#include "App.h"

ScriptManager *ScriptManager::mScriptManager=NULL;

ScriptManager* ScriptManager::getSingletonPtr( void )
{
	if ( !mScriptManager )
		{
			mScriptManager = new ScriptManager();
		}

	return mScriptManager;
}


ScriptManager::ScriptManager()
{

//	lua_State* L = OgreApplication::getSingleton().L;
//	interps.push_back(new LuaInterpreter(L));
//	interps.push_back(new PythonInterpreter());
}

ScriptManager::~ScriptManager()
{
}

void ScriptManager::execute(ScriptObject* so)
{
	if(!hasInterp(so->mType) || so->mCode=="") return;

	
	Interpreter* interp = getInterp(so->mType);

	interp->insertLine(so->mCode);

//	std::string out = interp->getOutput();
//	if(out!="")
//		cout << out << endl;
	interp->getOutput();

	interp->clearOutput();
}

bool ScriptManager::hasInterp(const std::string& lang)
{
	std::vector<Interpreter*>::iterator it;
	for(it=interps.begin(); it!=interps.end(); ++it)
		{
			if((*it)->lang==lang) return true;
		}
	return false;
}

Interpreter* ScriptManager::getInterp(const std::string& lang)
{
	std::vector<Interpreter*>::iterator it;
	for(it=interps.begin(); it!=interps.end(); ++it)
		{
			if((*it)->lang==lang) return *it;
		}
	return NULL;
}
